package cn.edu.ujs.coor.request;

import cn.edu.ujs.coor.util.BeanUtil;
import lombok.Data;

import java.io.Serializable;

/**
 * 序列化 请求参数父类
 */
@Data
public class BaseRequest<Entity> implements Serializable {

    /**
     * 备注
     */
    protected String remark;

    /**
     * 实例化Entity对象, 并且属性赋值
     * @param entityClass
     * @return
     */
    public Entity convertToEntity(Class<Entity> entityClass) {
        Entity entity = null;
        try {
            entity = entityClass.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        BeanUtil.copyBeanIgnoreNull(entity, this);
        return entity;
    }

    /**
     * Entity对象属性覆盖赋值
     * @param entity
     * @return
     */
    public Entity copyToEntity(Entity entity) {
        BeanUtil.copyBeanIgnoreNull(entity, this);
        return entity;
    }
}
